require "Dialogs"

Encounter["StartCounting"] = nil
timer = 0
transition = 0
glowtimer = 0
if not GetRealGlobal("Extras") then
	seleccion = 1
else
	seleccion = 14
end
phaseanim = 1
tableaux = 0
if not GetRealGlobal("Extras") then
	CentroX = 0
else
	CentroX = 800
end
Seccion = 1
seccionL = 1
ExtrasS = (GetRealGlobal("Extras") or 1)
ExtrasD = 2
if GetRealGlobal("Extras") then
	confirmed = 0
end

Player.lv = 19
Player.hp = 92
Encounter.Call("ConfigurateKR", {true, false})
NewAudio.CreateChannel("Menu")
NewAudio.CreateChannel("Creditos")
NewAudio.CreateChannel("Logros")
NewAudio.PlaySound("Menu", "Chiptune", true, 0)
NewAudio.PlaySound("Logros", "Chiptune", true, 0)
NewAudio.PlaySound("Creditos", "Snowdin Town Music Box by Shigurizu Chan", true, 0)
NewAudio.SetPitch("Menu", 0.35)

A = CreateSprite("Pixel", "Top")
A.MoveTo(320, 240)
A.Scale(640, 480)
A.color = {0,0,0}
LogrosM = CreateSprite("Menu/LogrosBG","Top")
LogrosM.MoveTo(-480, 240)
Logos = {}
Iconos = {}
local contador1 = tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 1, 1)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 2, 2)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 3, 3)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 4, 4)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 5, 5)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante1"), 6, 6))
local contador2 = tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 1, 1)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 2, 2)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 3, 3)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 4, 4)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 5, 5)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 6, 6)) + tonumber(string.sub(GetAlMightyGlobal("ProgresoProgresivamenteProgresante2"), 7, 7))
local contador3 = tonumber(string.sub(GetAlMightyGlobal("Archivimentazo"), 7, 7))
if contador1 == 6 then
	contador1 = "[color:ffff00]("..contador1
else
	contador1 = "[color:808080]("..contador1
end
if contador2 == 7 then
	contador2 = "[color:ffff00]("..contador2
else
	contador2 = "[color:808080]("..contador2
end
if contador3 == 5 then
	contador3 = "[color:ffff00]("..contador3
else
	contador3 = "[color:808080]("..contador3
end
Messages = {{"Murderer", "Asesino", "Get the [color:ff0000]Genocide[color:ffffff]\rEnding", "Consigue el\rFinal [color:ff0000]Genocida[color:ffffff]"}, {"Last Chance", "Último Chance", "Get the [color:00ffff]Good[color:ffffff]\rEnding", "Consigue el\rFinal [color:00ffff]Bueno[color:ffffff]"}, {"Regret", "Arrepentimiento", "Get the\r[color:00ff00]Remorseful[color:ffffff]\rEnding", "Consigue el\rFinal [color:00ff00]Arrepentido[color:ffffff]"}, {"Traitor", "Traidor", "Get the [color:ff006e]Betrayal[color:ffffff]\rEnding", "Consigue el\rFinal [color:ff006e]Traicionero[color:ffffff]"}, {"Words can hurt", "Las palabras\rpueden lastimar", "Get the [color:b200ff]Invalid[color:ffffff]\rEnding", "Consigue el\rFinal [color:b200ff]Invalido[color:ffffff]"}, {"Captured Human", "Humano Capturado", "Be [color:ff0000]captured[color:ffffff] by\r[color:ffff00]Papyrus", "Se [color:ff0000]capturado[color:ffffff] por\r[color:ffff00]Papyrus"}, {"Hide and Seek", "Escondite", "Come on\r\rNo need to [color:ff0000]hide[color:ffffff]\rfive consecutive\rtimes\r\rAre you shy?[MoveX:-91][MoveY:-92]"..contador3.."/5)", "Vamos\r\rNo hay necesidad\rde [color:ff0000]esconderse[color:ffffff] 5\rveces seguidas\r\rEres timido?[MoveX:-85][MoveY:-92]"..contador3.."/5)"}, {"EGG", "EGG", "Defeat an [color:ffff00]Egg\rDog", "Derrota un [color:ffff00]Egg\rDog"}, {"Investigator", "Investigador", "[color:ff0000]Check[color:ffffff] all\renemies in [color:ffff00]all\rphases[MoveX:8][MoveY:-236]"..contador1.."/6)", "[color:ff0000]Checa[color:ffffff] todos los\renemigos en\r[color:ffff00]todas las fases[MoveX:-133][MoveY:-236]"..contador1.."/6)"}, {"Coward", "Cobarde", "[color:ff0000]Run[color:ffffff] like if\rthere was\rnothing better\rto do[MoveX:14][MoveY:-200]"..contador2.."/7)", "[color:ff0000]Corre[color:ffffff] como si no\rhubiera nada\rmejor que hacer[MoveX:-135][MoveY:-236]"..contador2.."/7)"}, {"Manipulator", "Manipulador", "You sure enjoy\rseeing them\rsuffer, don't\ryou?\r\rYou even [color:ff0000]play[color:ffffff]\rwith their [color:ffff00]lives", "Seguro disfrutas\rverlos sufrir, no\res asi?\r\rIncluso [color:ff0000]juegas[color:ffffff]\rcon sus [color:ffff00]vidas"}, {"I'm not hungry", "No tengo hambre", "Complete\rDisbelief from\r[color:ffff00]phase 1 to 4\r[color:ff0000]without using\rany item", "Completa\rDisbelief desde\r[color:ffff00]la fase 1 hasta\rla 4 [color:ff0000]sin usar\rningun objeto"}, {"Pasta Master", "Maestro de Pasta", "[color:ff0000]Judge[color:ffffff] the [color:ffff00]Cold\rSpaghetti[color:ffffff] of\r[color:ffff00]Papyrus", "[color:ff0000]Juzga[color:ffffff] el\r[color:ffff00]Spaghetti Frío\r[color:ffffff]de [color:ffff00]Papyrus"}, {"UnderCraft", "UnderCraft", "[color:ff0000]Die[color:ffffff] in the style\rof [color:rainbow]Minecraft", "[color:ff0000]Muere[color:ffffff] en el\restilo de\r[color:rainbow]Minecraft"}, {"A new challenger\rhas appeared", "Un nuevo retador\ra aparecido", "[color:ffff00]Challenge Undyne[color:ffffff]\rand [color:ff0000]don't get\rhit[color:ffffff] while you're\r[color:00ff00]green", "[color:ffff00]Reta a Undyne[color:ffffff] y\r[color:ff0000]no recibas daño[color:ffffff]\rmientras eres\r[color:00ff00]verde"}, {"DON'T TOUCH THE\rCHILD!", "NO TOQUES AL\rNIÑO!", "Do a [color:rainbow]NO HIT[color:rainbow][color:ffffff] in\r[color:ffff00]Phase 1", "[color:rainbow]NO RECIBAS DAÑO[color:rainbow][color:ffffff]\ren la [color:ffff00]fase 1"}, {"DO YOU HAVE A\rLIFE?!", "TIENES UNA VIDA?!", "I'll be direct\rComplete\rDisbelief from\r[color:ffff00]phase 1 to 4[color:ffffff]\r[color:rainbow]WITHOUT GETTING\rHIT[color:rainbow]\rDo you think\ryou can do it?", "Sere directo\rCompleta\rDisbelief desde\r[color:ffff00]la fase 1 hasta\rla 4[color:ffffff] sin [color:rainbow]RECIBIR\rDAÑO[color:rainbow]\rCrees poder\rhacerlo?"}, {"SPOOKY", "Espantoso", "[effect:shake]DON'T YOU DARE\r[effect:none][color:070707]PRESS H", "[effect:shake]NO TE ATREVAS\r[effect:none][color:070707]A PRESIONAR H"}, {"Double Lesson", "Doble Lección", "Double Trouble\r\r[color:ffff00]Papyrus[color:ffffff] has used\rDouble Team!", "Doble Problema\r\r[color:ffff00]Papyrus[color:ffffff] ha usado\rDoble Equipo!"}, {"Perseverance", "Perseverancia", "Keep going\r\r[color:ffff00]Don't give up[color:ffffff]\r\rEven if it\rlooks impossible", "Sigue adelante\r\r[color:ffff00]No te rindas[color:ffffff]\r\rIncluso si\rparece imposible"}, {"Annoying Dog", "Perro Molesto", "[effect:shake]Beware of the\r[color:ffff00]DOG[color:ffffff]!", "[effect:shake]Cuidado con el\r[color:ffff00]PERRO[color:ffffff]!"}, {"Dirty Killer\rBrother", "Sucio Asesino de\rHermanos", "[color:ffff00]Papyrus[color:ffffff] misses\r[effect:shake][color:ff0000]his brother[color:ffffff][effect:none] so\rmuch...", "[color:ffff00]Papyrus[color:ffffff] extraña\rmucho a [effect:shake][color:ff0000]su\rhermano..."}, {"Spaghetti Murder", "Asesinato de\rSpaghetti", "[effect:shake][color:ff0000]SOMEBODY TOUCHA\rMY SPAGHET!", "[effect:shake][color:ff0000]SOMEBODY TOUCHA\rMY SPAGHET"}, {"I'm out of here", "Me voy de aquí", "How the [effect:shake]F###?![effect:none]\r\rHow did that\rthing [color:ff0000]run away[color:ffffff]?!", "Que [effect:shake]ch#######?![effect:none]\r\rComo esa cosa\r[color:ff0000]huyo[color:ffffff]?!"}, {"The Comedian", "El Comediante", "Hit [color:ffff00]Sans[color:ffffff] if you\rcan", "Golpea a [color:ffff00]Sans[color:ffffff]\rsi puedes"}, {"SIKE!", "SIKE!", "Can you [color:ff0000]DIE[color:ffffff]\rduring [color:ffff00]your\rturn[color:ffffff]?\r\rThere's only one\rway to find that\rout!", "Puedes [color:ff0000]MORIR[color:ffffff]\rdurante tu\rturno?\r\rSolo hay una\rmanera de\raveriguarlo!"}}
for i=0,2 do
	for j=0,5 do
		local spruait1 = CreateSprite("Pixel")
		spruait1.Scale(90, 90)
		spruait1.SetParent(LogrosM)
		spruait1.MoveTo(-263 + 105*j, 144 - 110*i)
		table.insert(Logos, spruait1)
		local spruait2 = CreateSprite("Menu/Archievements/Unknown")
		if (string.sub(GetAlMightyGlobal("Archivimentazo"), i*6 + j + 1, i*6 + j + 1) == "1" and i*6 + j + 1 ~= 7) or (string.sub(GetAlMightyGlobal("Archivimentazo"), 7, 7) == "5" and i*6 + j + 1 == 7) then
			spruait2.Set("Menu/Archievements/"..(i*6 + j + 1))
			spruait2.SetVar("Unlocked", true)
		end
		spruait2.SetParent(LogrosM)
		spruait2.MoveTo(-263 + 105*j, 144 - 110*i)
		table.insert(Iconos, spruait2)
	end
end
for i=0,1 do
	for j=0,5 do
		if i ~= 1 or j < 2 then
			local spruait2 = CreateSprite("Menu/Archievements/Unknown")
			if string.sub(GetAlMightyGlobal("Archivimentazo"), i*6 + j + 19, i*6 + j + 19) == "1" then
				spruait2.Set("Menu/Archievements/"..(i*6 + j + 19))
				spruait2.SetVar("Unlocked", true)
			end
			spruait2.SetParent(LogrosM)
			spruait2.MoveTo(-263 + 105*j, 144 - 110*i)
			spruait2.alpha = 0
			table.insert(Iconos, spruait2)
		end
	end
end
CreditosM = CreateSprite("Menu/CreditosBG","Top")
CreditosM.MoveTo(320, 800)
VolverL = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Volver")
VolverL.SetParent(LogrosM)
VolverL.MoveTo(0, -220)
Arrow3 = CreateSprite("Menu/Flecha")
Arrow3.SetParent(LogrosM)
Arrow3.MoveTo(80, -220)
Arrow4 = CreateSprite("Menu/Flecha")
Arrow4.SetParent(LogrosM)
Arrow4.rotation = 180
Arrow4.MoveTo(-80, -220)
BoxL = CreateSprite("Menu/Box")
BoxL.SetParent(LogrosM)
BoxL.alpha = 0
BoxL.MoveTo(0, 20)
VolverC = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Volver")
VolverC.SetParent(CreditosM)
VolverC.MoveTo(0, -220)
CreditosC = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/CreditosC")
CreditosC.SetParent(CreditosM)
CreditosC.MoveTo(0, 210)
DatoC = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Seccion 1")
DatoC.SetParent(CreditosM)
DatoC.MoveTo(0, -15)
Arrow1 = CreateSprite("Menu/Flecha")
Arrow1.SetParent(CreditosM)
Arrow1.MoveTo(80, -220)
Arrow2 = CreateSprite("Menu/Flecha")
Arrow2.SetParent(CreditosM)
Arrow2.rotation = 180
Arrow2.MoveTo(-80, -220)
Menu = CreateSprite("Rotatory Arena Pixel","Top")
if not GetRealGlobal("Extras") then
	Menu.MoveTo(320, 240)
else
	Menu.MoveTo(-480, 240)
end
Menu.alpha = 0
BG = CreateSprite("Menu/Fondo","Top")
-- BG = CreateSprite("Rotatory Arena Pixel","Top")
-- BG.Scale(640, 480)
BG.SetParent(Menu)
if GetAlMightyGlobal("Archivimentazo") == "111111511111111"..string.sub(GetAlMightyGlobal("Archivimentazo"), 16) then
	Trofeo = CreateSprite("Menu/Trofeo","Top")
	Trofeo.SetParent(Menu)
	Trofeo.MoveTo(260, 160)
end
ExtrasM = CreateSprite("Rotatory Arena Pixel","Top")
if not GetRealGlobal("Extras") then
	ExtrasM.MoveTo(1320, 240)
else
	ExtrasM.MoveTo(320, 240)
end
ExtrasM.alpha = 0
TituloE = CreateSprite("Menu/EXTRAS Bt","Top")
TituloE.SetParent(ExtrasM)
TituloE.MoveTo(0, 160)
OptionsE = {CreateSprite("Menu/Extras/1","Top"), CreateSprite("Menu/Extras/2","Top"), CreateSprite("Menu/Extras/3","Top"), CreateSprite("Menu/Extras/4","Top"), CreateSprite("Menu/Extras/5","Top"), CreateSprite("Menu/Extras/6","Top"), CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/VolverE","Top")}
for i=1,7 do
	OptionsE[i].SetParent(ExtrasM)
end
OptionsE[1].MoveTo(-172, 80)
OptionsE[2].MoveTo(-180, 35)
OptionsE[3].MoveTo(-196, -10)
OptionsE[4].MoveTo(-179.5, -55)
OptionsE[5].MoveTo(-172, -100)
OptionsE[6].MoveTo(-188, -145)
OptionsE[7].MoveTo(-239, -200)
Screen = CreateSprite("Menu/Previews/1","Top")
Screen.SetAnimation({"Distorsion/1","Distorsion/2","Distorsion/3"}, 3/60)
Screen.SetParent(ExtrasM)
Screen.Scale(1, 1)
Screen.color = {0.5, 0.5, 0.5}
Screen.MoveTo(140, -60)
Aux = CreateSprite("Rotatory Arena Pixel")
Aux.SetParent(Menu)
Aux.MoveTo(0, 0)
Aux.alpha = 0
PBone1 = CreateSprite("Menu/Phase 2/BackBone")
PBone1.SetParent(Aux)
PBone1.MoveTo(302, -98)
PBone1.alpha = 0
PBody = CreateSprite("Menu/Phase 1/Body")
PBody.SetParent(Aux)
PBody.MoveTo(140, -68)
PJaw = CreateSprite("Menu/Phase 1/Jaw")
PJaw.SetParent(PBody)
PJaw.MoveTo(14, -21)
-- PJaw.alpha = 0 --Remove
PHead = CreateSprite("Menu/Phase 1/Head 1")
PHead.SetParent(PBody)
PHead.MoveTo(-53, 70)
-- PHead.alpha = 0 --Remove
PGlow = CreateSprite("Menu/Phase 2/Glow")
PGlow.SetParent(PBody)
PGlow.Scale(0.5, 0.5)
PGlow.MoveTo(-22, 51)
PGlow.alpha = 0
PBone2 = CreateSprite("Menu/Phase 2/Bone")
PBone2.SetParent(PBody)
PBone2.MoveTo(-200, -127)
PBone2.alpha = 0
Glitch = CreateSprite("Menu/Glitch 1")
Glitch.SetParent(Menu)
Glitch.MoveTo(90, -68)
Glitch.alpha = 0
Glitch.Set("Menu/Glitch 2")
Glitch.Set("Menu/Glitch 3")
Glitch.Set("Menu/Glitch 4")
Glitch.Set("Menu/Glitch 5")
Glitch.Set("Menu/Glitch 1")
Disbelief = CreateSprite("Menu/Disbelief")
Disbelief.SetParent(Menu)
Disbelief.Scale(300/826, 300/826)
Disbelief.MoveTo(-160, 140)
Soul = CreateSprite("Specials/Soul")
Soul.SetParent(Menu)
Soul.color = {1,0,0}
Soul.MoveTo(-280, 14)
Soul.alpha = 0
Empezar = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Empezar")
Empezar.SetParent(Menu)
Empezar.SetVar("timer", 0)
Empezar.MoveTo(-220, 10)
Idioma = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Idioma")
Idioma.SetParent(Menu)
Idioma.SetVar("timer", 0)
Idioma.MoveTo(-140, 10)
Logros = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Logros")
Logros.SetParent(Menu)
Logros.SetVar("timer", 0)
Logros.MoveTo(-180, -30)
Extras = CreateSprite("Menu/Extras")
Extras.SetParent(Menu)
Extras.SetVar("timer", 0)
Extras.MoveTo(-228, -70)
Version = CreateSprite("Menu/Version")
Version.SetParent(Menu)
Version.color = {0.4,0.4,0.4}
Version.MoveTo(-265, -224)
Creditos = CreateSprite("Menu/"..GetAlMightyGlobal("Idioma").."/Creditos")
Creditos.SetParent(Menu)
Creditos.SetVar("timer", 0)
Creditos.MoveTo(-212, -110)
Black = CreateSprite("Rotatory Arena Pixel","Top")
Black.Scale(640, 480)
Black.MoveTo(320, 240)
Black.color = {0,0,0}

SetRealGlobal("Extras", nil)

Nieve = {}

function Update()
	timer = timer + 1
	if Black.alpha > 0 and timer <= 100 then
		Black.alpha = Black.alpha - 0.01
		NewAudio.SetVolume("Menu", 1 - Black.alpha)
	end
	if timer%20 == 0 then
		local Spruait = CreateSprite("Menu/Snow")
		Spruait.SetParent(CreditosM)
		Spruait.color = {0.75,0.75,0.75}
		Spruait.alpha = 0.66
		table.insert(Nieve, {Sprite = Spruait, Y = 250, X = math.random(-320, 320), Ang = math.random(360)})
	end
	if timer == 100 then
		Audio.PlaySound("pip")
	elseif timer > 100 then
		if not confirmed then
			if Soul.alpha < 1 then
				Soul.alpha = Soul.alpha + 0.02
			end
			if Input.Down == 1 and Input.Up == 0 and seleccion < 5 then
				seleccion = seleccion + 1
				Audio.PlaySound("pip")
			elseif Input.Down == 0 and Input.Up == 1 and seleccion > 1 then
				seleccion = seleccion - 1
				Audio.PlaySound("pip")
			end
		else
			if Soul.alpha > 0 then
				Soul.alpha = Soul.alpha - 0.02
			end
		end
		if seleccion == 1 and Empezar.GetVar("timer") < 20 then
			Empezar.SetVar("timer", Empezar.GetVar("timer") + 1)
			Empezar.color = {1,1,0}
		elseif seleccion ~= 1 and Empezar.GetVar("timer") > 0 then
			Empezar.SetVar("timer", Empezar.GetVar("timer") - 1)
			Empezar.color = {1,1,1}
		end
		if seleccion == 2 and Idioma.GetVar("timer") < 20 then
			Idioma.SetVar("timer", Idioma.GetVar("timer") + 1)
			Idioma.color = {1,1,0}
		elseif seleccion ~= 2 and Idioma.GetVar("timer") > 0 then
			Idioma.SetVar("timer", Idioma.GetVar("timer") - 1)
			Idioma.color = {1,1,1}
		end
		if seleccion == 3 and Logros.GetVar("timer") < 20 then
			Logros.SetVar("timer", Logros.GetVar("timer") + 1)
			Logros.color = {1,1,0}
		elseif seleccion ~= 3 and Logros.GetVar("timer") > 0 then
			Logros.SetVar("timer", Logros.GetVar("timer") - 1)
			Logros.color = {1,1,1}
		end
		if seleccion == 4 and Extras.GetVar("timer") < 20 then
			Extras.SetVar("timer", Extras.GetVar("timer") + 1)
			Extras.color = {1,1,0}
		elseif seleccion ~= 4 and Extras.GetVar("timer") > 0 then
			Extras.SetVar("timer", Extras.GetVar("timer") - 1)
			Extras.color = {1,1,1}
		end
		if seleccion == 5 and Creditos.GetVar("timer") < 20 then
			Creditos.SetVar("timer", Creditos.GetVar("timer") + 1)
			Creditos.color = {1,1,0}
		elseif seleccion ~= 5 and Creditos.GetVar("timer") > 0 then
			Creditos.SetVar("timer", Creditos.GetVar("timer") - 1)
			Creditos.color = {1,1,1}
		end
		if Input.Confirm == 1 and not confirmed then
			Audio.PlaySound("confirm")
			confirmed = 0
			transition = 0
			seleccion = seleccion + 5
		end
		if confirmed then
			confirmed = confirmed + 1
		end
		if seleccion == 1 and Soul.y < 14 then
			Soul.MoveTo(Soul.x, math.min(Soul.y + 4, 14))
		elseif seleccion == 2 then
			if Soul.y < -30 then
				Soul.MoveTo(Soul.x, math.min(Soul.y + 4, -30))
			elseif Soul.y > -30 then
				Soul.MoveTo(Soul.x, math.max(Soul.y - 4, -30))
			end
		elseif seleccion == 3 then
			if Soul.y < -68 then
				Soul.MoveTo(Soul.x, math.min(Soul.y + 4, -68))
			elseif Soul.y > -68 then
				Soul.MoveTo(Soul.x, math.max(Soul.y - 4, -68))
			end
		elseif seleccion == 4 then
			if Soul.y < -110 then
				Soul.MoveTo(Soul.x, math.min(Soul.y + 4, -110))
			elseif Soul.y > -110 then
				Soul.MoveTo(Soul.x, math.max(Soul.y - 4, -110))
			end
		elseif seleccion == 5 and Soul.y > -150 then
			Soul.MoveTo(Soul.x, math.max(Soul.y - 4, -150))
		elseif seleccion == 6 then
			transition = transition + 1
			if transition > 30 and transition <= 210 then
				BG.Scale(1.5 - math.cos(math.rad(transition - 30))/2, 1.5 - math.cos(math.rad(transition - 30))/2)
				PHead.Scale(BG.xscale, BG.yscale)
				PJaw.Scale(BG.xscale, BG.yscale)
				PBody.Scale(BG.xscale, BG.yscale)
				PGlow.Scale(BG.xscale, BG.yscale)
				PBone1.Scale(BG.xscale, BG.yscale)
				PBone2.Scale(BG.xscale, BG.yscale)
				Glitch.Scale(BG.xscale, BG.yscale)
				Empezar.Scale(BG.xscale, BG.yscale)
				Idioma.Scale(BG.xscale, BG.yscale)
				Logros.Scale(BG.xscale, BG.yscale)
				Extras.Scale(BG.xscale, BG.yscale)
				Creditos.Scale(BG.xscale, BG.yscale)
				Version.Scale(BG.xscale, BG.yscale)
				Disbelief.Scale(300/826*BG.xscale, 300/826*BG.yscale)
				Menu.MoveTo(160 + 160*math.cos(math.rad(transition - 30)), 300 - 60*math.cos(math.rad(transition - 30)))
				PGlow.MoveTo(-22*BG.xscale, 51*BG.yscale)
				Glitch.MoveTo(90*BG.xscale, -68*BG.yscale)
				Disbelief.MoveTo(-160*BG.xscale, 140*BG.yscale)
				Soul.MoveTo(-280*BG.xscale, 14*BG.yscale)
				Version.MoveTo(-265*BG.xscale, -224*BG.yscale)
			elseif transition > 240 and transition <= 330 then
				Black.alpha = (transition - 240)/90
				NewAudio.SetVolume("Menu", 1 - Black.alpha)
			elseif transition > 390 then
				EndAll = "Battle"
			end
			Empezar.color = {1,1,math.cos(math.rad(90/2*confirmed))}
		elseif seleccion == 7 then
			if GetAlMightyGlobal("Idioma") == "English" then
				SetAlMightyGlobal("Idioma", "Spanish")
			else
				SetAlMightyGlobal("Idioma", "English")
			end
			Empezar.Set("Menu/"..GetAlMightyGlobal("Idioma").."/Empezar")
			Idioma.Set("Menu/"..GetAlMightyGlobal("Idioma").."/Idioma")
			Logros.Set("Menu/"..GetAlMightyGlobal("Idioma").."/Logros")
			Creditos.Set("Menu/"..GetAlMightyGlobal("Idioma").."/Creditos")
			CreditosC.Set("Menu/"..GetAlMightyGlobal("Idioma").."/CreditosC")
			VolverC.Set("Menu/"..GetAlMightyGlobal("Idioma").."/Volver")
			VolverL.Set("Menu/"..GetAlMightyGlobal("Idioma").."/Volver")
			DatoC.Set("Menu/"..GetAlMightyGlobal("Idioma").."/Seccion "..Seccion)
			OptionsE[7].Set("Menu/"..GetAlMightyGlobal("Idioma").."/VolverE")
			confirmed = nil
			seleccion = seleccion - 5
		elseif seleccion == 8 then
			transition = transition + 1
			if transition > 30 and transition <= 150 then
				Menu.MoveTo(720 - 400*math.cos(math.rad(180/120*(transition - 30))), 240)
				NewAudio.SetVolume("Menu", math.cos(math.rad(180/120*(transition - 30))))
			elseif transition > 150 and transition <= 270 then
				LogrosM.MoveTo(-80 - 400*math.cos(math.rad(180/120*(transition - 150))), 240)
				NewAudio.SetVolume("Logros", 1 - math.cos(math.rad(180/120*(transition - 150))))
			elseif transition == 300 then
				seleccion = seleccion + 5
				Audio.PlaySound("pip")
				seccionL = 1
				transition = 1
			end
			Logros.color = {1,1,math.cos(math.rad(90/2*confirmed))}
		elseif seleccion == 9 then
			transition = transition + 1
			if transition > 30 and transition <= 150 then
				Menu.MoveTo(-80 + 400*math.cos(math.rad(180/120*(transition - 30))), 240)
				CentroX = 400 - 400*math.cos(math.rad(180/120*(transition - 30)))
			elseif transition > 150 and transition <= 270 then
				ExtrasM.MoveTo(720 + 400*math.cos(math.rad(180/120*(transition - 150))), 240)
			elseif transition == 300 then
				seleccion = seleccion + 5
				Audio.PlaySound("pip")
			end
			Extras.color = {1,1,math.cos(math.rad(90/2*confirmed))}
		elseif seleccion == 10 then
			transition = transition + 1
			if transition > 30 and transition <= 150 then
				Menu.MoveTo(320, -160 + 400*math.cos(math.rad(180/120*(transition - 30))))
				NewAudio.SetVolume("Menu", math.cos(math.rad(180/120*(transition - 30))))
			elseif transition > 150 and transition <= 270 then
				CreditosM.MoveTo(320, 640 + 400*math.cos(math.rad(180/120*(transition - 150))))
				NewAudio.SetVolume("Creditos", 1 - math.cos(math.rad(180/120*(transition - 150))))
			elseif transition == 300 then
				seleccion = seleccion + 5
				Audio.PlaySound("pip")
				VolverC.color = {1,1,0}
				transition = 2
			end
			Creditos.color = {1,1,math.cos(math.rad(90/2*confirmed))}
		elseif seleccion == 13 then
			if Input.Left == 1 then
				if seccionL == 1 then
					if transition == 19 then
						transition = transition + 2
					elseif transition%6 == 1 then
						transition = transition + 5
					else
						transition = transition - 1
					end
				else
					if transition == 19 then
						transition = transition + 2
					elseif transition == 1 then
						transition = transition + 5
					elseif transition == 7 then
						transition = transition + 1
					else
						transition = transition - 1
					end
				end
				Audio.PlaySound("pip")
			end
			if Input.Right == 1 then
				if seccionL == 1 then
					if transition == 21 then
						transition = transition - 2
					elseif transition%6 == 0 then
						transition = transition - 5
					else
						transition = transition + 1
					end
				else
					if transition == 21 then
						transition = transition - 2
					elseif transition == 6 then
						transition = transition - 5
					elseif transition == 8 then
						transition = transition - 1
					else
						transition = transition + 1
					end
				end
				Audio.PlaySound("pip")
			end
			if Input.Up == 1 then
				if seccionL == 1 then
					if transition >= 19 then
						transition = 15 + math.floor((transition - 19)/2)
					elseif transition <= 6 then
						transition = 18 + math.ceil(transition/2)
					else
						transition = transition - 6
					end
				else
					if transition >= 19 then
						transition = 3 + math.floor((transition - 19)/2)
					elseif transition <= 6 then
						transition = 18 + math.ceil(transition/2)
					else
						transition = transition - 6
					end
				end
				Audio.PlaySound("pip")
			end
			if Input.Down == 1 then
				if seccionL == 1 then
					if transition >= 19 then
						transition = 3 + math.floor((transition - 19)/2)
					elseif transition >= 13 then
						transition = 18 + math.ceil((transition - 12)/2)
					else
						transition = transition + 6
					end
				else
					if transition >= 19 then
						transition = 3 + math.floor((transition - 19)/2)
					elseif transition >= 7 then
						transition = 18 + math.ceil((transition - 6)/2)
					elseif transition >= 3 then
						transition = 18 + math.ceil(transition/2)
					else
						transition = transition + 6
					end
				end
				Audio.PlaySound("pip")
			end
			for i=1,#Logos do
				Logos[i].color = {1,1,1}
			end
			Arrow3.color = {1,1,1}
			VolverL.color = {1,1,1}
			Arrow4.color = {1,1,1}
			BoxL.alpha = 0
			Dialog("", "", "", "", 1)
			if transition <= 18 then
				Logos[transition].color = {1,1,0}
				BoxL.alpha = 1
				if transition%6 > 0 and transition%6 <= 3 then
					BoxL.x = Logos[transition].x + 185
				else
					BoxL.x = Logos[transition].x - 185
				end
				local mostrar = "[color:808080]"
				if seccionL == 1 then
					local acumulador = 0
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						acumulador = 1
					end
					if Iconos[transition].GetVar("Unlocked") then
						mostrar = "[color:ffff00]"..Messages[transition][1 + acumulador]
					else
						Messages[transition][1 + acumulador] = string.gsub(Messages[transition][1 + acumulador], "'", "a")
						Messages[transition][1 + acumulador] = string.gsub(Messages[transition][1 + acumulador], "!", "a")
						Messages[transition][1 + acumulador] = string.gsub(Messages[transition][1 + acumulador], "?", "a")
						Messages[transition][1 + acumulador] = string.gsub(Messages[transition][1 + acumulador], "\r", " ")
						local contador = 0
						for palabra in string.gmatch(Messages[transition][1 + acumulador], "%a+") do
							contador = contador + 1
							mostrar = mostrar..string.rep("?", string.len(palabra))
							if (transition >= 15 and transition <= 17 and contador == 3 + math.floor((transition - 15)/2)) or ((transition == 5 or transition == 17) and contador == 2 and acumulador == 1) then
								mostrar = mostrar.."\r"
							else
								mostrar = mostrar.." "
							end
						end
					end
					mostrar = mostrar.."\r[color:ffffff][MoveX:-2]------------------\r"..Messages[transition][3 + acumulador]
				else
					local acumulador = 0
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						acumulador = 1
					end
					if Iconos[transition + 18].GetVar("Unlocked") then
						mostrar = "[color:ffff00]"..Messages[transition + 18][1 + acumulador]
					else
						Messages[transition + 18][1 + acumulador] = string.gsub(Messages[transition + 18][1 + acumulador], "'", "a")
						Messages[transition + 18][1 + acumulador] = string.gsub(Messages[transition + 18][1 + acumulador], "!", "a")
						Messages[transition + 18][1 + acumulador] = string.gsub(Messages[transition + 18][1 + acumulador], "?", "a")
						Messages[transition + 18][1 + acumulador] = string.gsub(Messages[transition + 18][1 + acumulador], "\r", " ")
						local contador = 0
						for palabra in string.gmatch(Messages[transition + 18][1 + acumulador], "%a+") do
							contador = contador + 1
							mostrar = mostrar..string.rep("?", string.len(palabra))
							if (transition == 4 and contador == 2 + acumulador) or (transition == 5 and contador == 2 and acumulador == 1) then
								mostrar = mostrar.."\r"
							else
								mostrar = mostrar.." "
							end
						end
					end
					mostrar = mostrar.."\r[color:ffffff][MoveX:-2]------------------\r"..Messages[transition + 18][3 + acumulador]
				end
				Dialog(mostrar, {X = BoxL.x + 197, Y = BoxL.y + 447}, nil, nil, 1)
				Dialogues[1].DTiempoW = 0
				Dialogues[1].DSkip = "Instantaneo"
				DialogUpdate()
			elseif transition == 19 then
				Arrow4.color = {1,1,0}
			elseif transition == 20 then
				VolverL.color = {1,1,0}
			elseif transition == 21 then
				Arrow3.color = {1,1,0}
			end
			if Input.Confirm == 1 then
				if transition == 19 or transition == 21 then
					if seccionL == 1 then
						seccionL = 2
						for i=1,#Iconos do
							if i <= 18 then
								Iconos[i].alpha = 0
							else
								Iconos[i].alpha = 1
							end
						end
						for i=9,#Logos do
							Logos[i].alpha = 0
						end
					else
						seccionL = 1
						for i=1,#Iconos do
							if i <= 18 then
								Iconos[i].alpha = 1
							else
								Iconos[i].alpha = 0
							end
						end
						for i=9,#Logos do
							Logos[i].alpha = 1
						end
					end
					Audio.PlaySound("confirm")
				elseif transition == 20 then
					VolverL.color = {1,1,1}
					seleccion = seleccion + 5
					transition = 0
					Logros.color = {1,1,1}
					Audio.PlaySound("confirm")
				end
			end
		elseif seleccion == 14 then
			if Input.Down == 1 and Input.Up == 0 and ExtrasS < 7 then
				ExtrasS = ExtrasS + 1
				Audio.PlaySound("pip")
			elseif Input.Down == 0 and Input.Up == 1 and ExtrasS > 1 and ExtrasS <= 7 then
				ExtrasS = ExtrasS - 1
				Audio.PlaySound("pip")
			end
			if Input.Confirm == 1 and not ExtrasC then
				Audio.PlaySound("confirm")
				ExtrasC = 0
				ExtrasS = ExtrasS + 7
			end
			if ExtrasC then
				ExtrasC = ExtrasC + 1
			end
			if ExtrasS <= 6 then
				if ExtrasD == 2 then
					Screen.StopAnimation()
				end
				Screen.Set("Menu/Previews/"..ExtrasS)
				Screen.Scale(320/640, 240/480)
				ExtrasD = 1
			elseif not ExtrasC then
				if ExtrasD == 1 then
					Screen.SetAnimation({"Distorsion/1","Distorsion/2","Distorsion/3"}, 3/60)
					Screen.Scale(1, 1)
					ExtrasD = 2
				end
			end
			if ExtrasS == 1 then
				OptionsE[1].color = {1,1,0}
				OptionsE[2].color = {1,1,1}
				OptionsE[3].color = {1,1,1}
				OptionsE[4].color = {1,1,1}
				OptionsE[5].color = {1,1,1}
				OptionsE[6].color = {1,1,1}
				OptionsE[7].color = {1,1,1}
			elseif ExtrasS == 2 then
				OptionsE[1].color = {1,1,1}
				OptionsE[2].color = {1,1,0}
				OptionsE[3].color = {1,1,1}
				OptionsE[4].color = {1,1,1}
				OptionsE[5].color = {1,1,1}
				OptionsE[6].color = {1,1,1}
				OptionsE[7].color = {1,1,1}
			elseif ExtrasS == 3 then
				OptionsE[1].color = {1,1,1}
				OptionsE[2].color = {1,1,1}
				OptionsE[3].color = {1,1,0}
				OptionsE[4].color = {1,1,1}
				OptionsE[5].color = {1,1,1}
				OptionsE[6].color = {1,1,1}
				OptionsE[7].color = {1,1,1}
			elseif ExtrasS == 4 then
				OptionsE[1].color = {1,1,1}
				OptionsE[2].color = {1,1,1}
				OptionsE[3].color = {1,1,1}
				OptionsE[4].color = {1,1,0}
				OptionsE[5].color = {1,1,1}
				OptionsE[6].color = {1,1,1}
				OptionsE[7].color = {1,1,1}
			elseif ExtrasS == 5 then
				OptionsE[1].color = {1,1,1}
				OptionsE[2].color = {1,1,1}
				OptionsE[3].color = {1,1,1}
				OptionsE[4].color = {1,1,1}
				OptionsE[5].color = {1,1,0}
				OptionsE[6].color = {1,1,1}
				OptionsE[7].color = {1,1,1}
			elseif ExtrasS == 6 then
				OptionsE[1].color = {1,1,1}
				OptionsE[2].color = {1,1,1}
				OptionsE[3].color = {1,1,1}
				OptionsE[4].color = {1,1,1}
				OptionsE[5].color = {1,1,1}
				OptionsE[6].color = {1,1,0}
				OptionsE[7].color = {1,1,1}
			elseif ExtrasS == 7 then
				OptionsE[1].color = {1,1,1}
				OptionsE[2].color = {1,1,1}
				OptionsE[3].color = {1,1,1}
				OptionsE[4].color = {1,1,1}
				OptionsE[5].color = {1,1,1}
				OptionsE[6].color = {1,1,1}
				OptionsE[7].color = {1,1,0}
			else
				OptionsE[1].color = {1,1,1}
				OptionsE[2].color = {1,1,1}
				OptionsE[3].color = {1,1,1}
				OptionsE[4].color = {1,1,1}
				OptionsE[5].color = {1,1,1}
				OptionsE[6].color = {1,1,1}
				OptionsE[7].color = {1,1,1}
			end
			if ExtrasS >= 8 and ExtrasS < 14 then
				if ExtrasC > 30 and ExtrasC <= 210 then
					TituloE.Scale(1.5 - math.cos(math.rad((ExtrasC - 30)))/2, 1.5 - math.cos(math.rad((ExtrasC - 30)))/2)
					for i=1,#OptionsE do
						OptionsE[i].Scale(1.5 - math.cos(math.rad((ExtrasC - 30)))/2, 1.5 - math.cos(math.rad((ExtrasC - 30)))/2)
					end
					Screen.Scale(0.75 - math.cos(math.rad((ExtrasC - 30)))/4, 0.75 - math.cos(math.rad((ExtrasC - 30)))/4)
					ExtrasM.MoveTo(180 + 140*math.cos(math.rad((ExtrasC - 30))), 300 - 60*math.cos(math.rad((ExtrasC - 30))))
					TituloE.MoveTo(0, 160*TituloE.yscale)
					OptionsE[1].MoveTo(-172*OptionsE[1].xscale, 80*OptionsE[1].yscale)
					OptionsE[2].MoveTo(-180*OptionsE[2].xscale, 35*OptionsE[2].yscale)
					OptionsE[3].MoveTo(-196*OptionsE[3].xscale, -10*OptionsE[3].yscale)
					OptionsE[4].MoveTo(-179.5*OptionsE[4].xscale, -55*OptionsE[4].yscale)
					OptionsE[5].MoveTo(-172*OptionsE[5].xscale, -100*OptionsE[5].yscale)
					OptionsE[6].MoveTo(-188*OptionsE[6].xscale, -145*OptionsE[6].yscale)
					OptionsE[7].MoveTo(-239*OptionsE[7].xscale, -200*OptionsE[7].yscale)
					Screen.MoveTo(140*Screen.xscale*2, -60*Screen.yscale*2)
					if ExtrasC > 120 and ExtrasC <= 210 then
						Black.alpha = (ExtrasC - 90)/90
						NewAudio.SetVolume("Menu", 1 - Black.alpha)
					end
				elseif ExtrasC > 270 then
					if ExtrasS == 8 then
						EndAll = "MenuG"
					elseif ExtrasS == 9 then
						EndAll = "MenuJ"
					elseif ExtrasS == 10 then
						EndAll = "Tension Level"
					elseif ExtrasS == 11 then
						EndAll = "Peer Gynt Level"
					elseif ExtrasS == 12 then
						EndAll = "Death Egg Robot Attacks - Endless"
					elseif ExtrasS == 13 then
						EndAll = "Bowsy Attacks"
					end
				end
			elseif ExtrasS == 14 then
				ExtrasS = 1
				ExtrasC = nil
				seleccion = seleccion + 5
				transition = 0
				Extras.color = {1,1,1}
			end
		elseif seleccion == 15 then
			if Input.Left == 1 and Input.Right == 0 and transition > 1 then
				Audio.PlaySound("pip")
				transition = transition - 1
			elseif Input.Right == 1 and Input.Left == 0 and transition < 3 then
				Audio.PlaySound("pip")
				transition = transition + 1
			end
			if transition == 1 then
				if Input.Confirm == 1 then
					Audio.PlaySound("confirm")
					Seccion = Seccion - 1
					if Seccion <= 0 then
						Seccion = Seccion + 4
					end
					DatoC.Set("Menu/"..GetAlMightyGlobal("Idioma").."/Seccion "..Seccion)
				end
				Arrow2.color = {1,1,0}
			else
				Arrow2.color = {1,1,1}
			end
			if transition == 2 then
				VolverC.color = {1,1,0}
				if Input.Confirm == 1 then
					Audio.PlaySound("confirm")
					VolverC.color = {1,1,1}
					Creditos.color = {1,1,1}
					transition = 0
					seleccion = seleccion + 5
				end
			else
				VolverC.color = {1,1,1}
			end
			if transition == 3 then
				if Input.Confirm == 1 then
					Audio.PlaySound("confirm")
					Seccion = Seccion + 1
					if Seccion >= 5 then
						Seccion = Seccion - 4
					end
					DatoC.Set("Menu/"..GetAlMightyGlobal("Idioma").."/Seccion "..Seccion)
				end
				Arrow1.color = {1,1,0}
			else
				Arrow1.color = {1,1,1}
			end
		elseif seleccion == 18 then
			transition = transition + 1
			if transition > 30 and transition <= 150 then
				LogrosM.MoveTo(-80 + 400*math.cos(math.rad(180/120*(transition - 30))), 240)
				NewAudio.SetVolume("Logros", math.cos(math.rad(180/120*(transition - 30))))
			elseif transition > 150 and transition <= 270 then
				Menu.MoveTo(720 + 400*math.cos(math.rad(180/120*(transition - 150))), 240)
				NewAudio.SetVolume("Menu", 1 - math.cos(math.rad(180/120*(transition - 150))))
			elseif transition == 300 then
				seleccion = seleccion - 15
				Audio.PlaySound("pip")
				confirmed = nil
				for i=1,#Iconos do
					if i <= 18 then
						Iconos[i].alpha = 1
					else
						Iconos[i].alpha = 0
					end
				end
				for i=10,#Logos do
					Logos[i].alpha = 1
				end
			end
		elseif seleccion == 19 then
			transition = transition + 1
			if transition > 30 and transition <= 150 then
				ExtrasM.MoveTo(720 - 400*math.cos(math.rad(180/120*(transition - 30))), 240)
			elseif transition > 150 and transition <= 270 then
				Menu.MoveTo(-80 - 400*math.cos(math.rad(180/120*(transition - 150))), 240)
				CentroX = 400 + 400*math.cos(math.rad(180/120*(transition - 150)))
			elseif transition == 300 then
				seleccion = seleccion - 15
				confirmed = nil
				Audio.PlaySound("pip")
			end
		elseif seleccion == 20 then
			transition = transition + 1
			if transition > 30 and transition <= 150 then
				CreditosM.MoveTo(320, 640 - 400*math.cos(math.rad(180/120*(transition - 30))))
				NewAudio.SetVolume("Creditos", math.cos(math.rad(180/120*(transition - 30))))
			elseif transition > 150 and transition <= 270 then
				Menu.MoveTo(320, -160 - 400*math.cos(math.rad(180/120*(transition - 150))))
				NewAudio.SetVolume("Menu", 1 - math.cos(math.rad(180/120*(transition - 150))))
			elseif transition == 300 then
				seleccion = seleccion - 15
				confirmed = nil
				Audio.PlaySound("pip")
			end
		end
	end
	Empezar.MoveTo((-220 + 18*math.sin(math.rad(90/20*Empezar.GetVar("timer"))))*BG.xscale, 10*BG.yscale)
	Idioma.MoveTo((-140 + 18*math.sin(math.rad(90/20*Idioma.GetVar("timer"))))*BG.xscale, -30*BG.yscale)
	Logros.MoveTo((-180 + 18*math.sin(math.rad(90/20*Logros.GetVar("timer"))))*BG.xscale, -70*BG.yscale)
	Extras.MoveTo((-228 + 18*math.sin(math.rad(90/20*Extras.GetVar("timer"))))*BG.xscale, -110*BG.yscale)
	Creditos.MoveTo((-212 + 18*math.sin(math.rad(90/20*Creditos.GetVar("timer"))))*BG.xscale, -150*BG.yscale)
	BG.MoveTo(CentroX + 10*math.sin(math.rad(90/54*timer))*BG.xscale, 10*math.sin(math.rad(90/65*timer))*BG.yscale)
	if timer%360 == 350 then
		Glitch.alpha = 1
		Glitch.Set("Menu/Glitch 1")
		PHead.alpha = 0
		PBody.alpha = 0
		PJaw.alpha = 0
		PGlow.alpha = 0
		PBone1.alpha = 0
		PBone2.alpha = 0
		actual = phaseanim
		phaseanim = 0
	elseif timer%360 == 352 then
		Glitch.Set("Menu/Glitch 2")
	elseif timer%360 == 354 then
		Glitch.Set("Menu/Glitch 3")
	elseif timer%360 == 356 then
		Glitch.Set("Menu/Glitch 4")
	elseif timer%360 == 358 then
		Glitch.Set("Menu/Glitch 5")
	elseif timer%360 == 0 then
		Glitch.alpha = 0
		repeat
			phaseanim = math.random(4)
		until phaseanim ~= actual
		actual = nil
		if phaseanim == 1 then
			PHead.alpha = 1
			PBody.alpha = 1
			PJaw.alpha = 1
			PBody.Set("Menu/Phase 1/Body")
		elseif phaseanim == 2 then
			PBody.alpha = 1
			PBone1.alpha = 1
			PBone2.alpha = 1
			PBody.Set("Menu/Phase 2/Body")
			PBone2.Set("Menu/Phase 2/Bone")
		elseif phaseanim == 3 then
			PBody.alpha = 1
			PBone2.alpha = 1
			PBody.Set("Menu/Phase 3/Body")
			PBone2.Set("Menu/Phase 3/Puno")
		else
			PBody.alpha = 1
			PBody.Set("Menu/Phase 4/Body")
		end
	end
	if timer%20 == 0 then
		PHead.Set("Menu/Phase 1/Head 1")
	elseif timer%20 == 5 then
		PHead.Set("Menu/Phase 1/Head 2")
	elseif timer%20 == 10 then
		PHead.Set("Menu/Phase 1/Head 3")
	elseif timer%20 == 15 then
		PHead.Set("Menu/Phase 1/Head 2")
	end
	PBody.MoveTo(140*BG.xscale, (-73 + 5*math.cos(math.rad(timer*2)))*BG.yscale)
	PHead.MoveTo(-53*BG.xscale, (67 + 3*math.cos(math.rad(timer*2)))*BG.yscale)
	PJaw.MoveTo(PHead.x + 67*BG.xscale, PHead.y - (100 + 3*math.cos(math.rad(timer*2)))*BG.yscale)
	if phaseanim == 2 then
		glowtimer = glowtimer + 1
		if glowtimer == 180 then
			PGlow.alpha = 1
			PGlow.Scale(0.2, 0.2)
		elseif glowtimer > 180 then
			PGlow.alpha = PGlow.alpha - 0.02
			PGlow.Scale(PGlow.xscale + 0.05, PGlow.yscale + 0.05)
			if PGlow.alpha <= 0 then
				glowtimer = 0
			end
		end
	end
	PBone1.rotation = 5 - 5*math.cos(math.rad(timer*2))
	PBone2.rotation = 5 - 5*math.cos(math.rad(timer*2))
	PBone1.MoveTo((297 - 57*math.sin(math.rad(PBone1.rotation)) + 5*math.cos(math.rad(timer*2)))*BG.xscale, (-165 + 57*math.cos(math.rad(PBone1.rotation)) + 10*math.cos(math.rad(timer*2)))*BG.yscale)
	PBone2.MoveTo((-190 + 10*math.cos(math.rad(timer*2)) - 45*math.sin(math.rad(PBone2.rotation)))*BG.xscale, (-182 + 45*math.cos(math.rad(PBone2.rotation)) + 10*math.cos(math.rad(timer*2)))*BG.yscale)
	for i=1,#Nieve do
		local Datos = Nieve[i - tableaux]
		Datos.Y = Datos.Y - 1
		Datos.Ang = Datos.Ang + 1
		Datos.Sprite.MoveTo(Datos.X + 10*math.sin(math.rad(Datos.Ang)), Datos.Y)
		if Datos.Y < -250 then
			Datos.Sprite.alpha = Datos.Sprite.alpha - 0.02
			if Datos.Sprite.alpha <= 0 then
				Datos.Sprite.Remove()
				table.remove(Nieve, i - tableaux)
				tableaux = tableaux + 1
			end
		end
	end
	tableaux = 0
	if EndAll then
		NewAudio.Stop("Menu")
		NewAudio.Stop("Creditos")
		NewAudio.Stop("Logros")
		NewAudio.DestroyChannel("Menu")
		NewAudio.DestroyChannel("Creditos")
		NewAudio.DestroyChannel("Logros")
		CreditosM.Remove()
		VolverC.Remove()
		VolverL.Remove()
		CreditosC.Remove()
		DatoC.Remove()
		Arrow1.Remove()
		Arrow2.Remove()
		Arrow3.Remove()
		Arrow4.Remove()
		Menu.Remove()
		BG.Remove()
		ExtrasM.Remove()
		TituloE.Remove()
		for i=1,#OptionsE do
			OptionsE[i].Remove()
		end
		Screen.Remove()
		Aux.Remove()
		PBone1.Remove()
		PBody.Remove()
		PJaw.Remove()
		PHead.Remove()
		PGlow.Remove()
		PBone2.Remove()
		Glitch.Remove()
		Disbelief.Remove()
		Soul.Remove()
		Empezar.Remove()
		Idioma.Remove()
		Logros.Remove()
		Extras.Remove()
		Version.Remove()
		Creditos.Remove()
		LogrosM.Remove()
		Black.Remove()
		A.Remove()
		for i=1,#Nieve do
			Nieve[i].Sprite.Remove()
		end
		if EndAll != "Battle" then
			Encounter["nextwaves"] = {EndAll}
			State("ACTIONSELECT")
			State("DEFENDING")
		else
			if not GetAlMightyGlobal("WarningDisbelief") then
				Encounter["nextwaves"] = {"Hold on"}
				State("ACTIONSELECT")
				State("DEFENDING")
			else
				Encounter.Call("Reset", true)
			end
		end
	end
end